# -- coding: utf-8 -- 
from django.contrib import admin
from books.models import Publisher, Author, Book

class AuthorAdmin(admin.ModelAdmin): 
    list_display = ('first_name', 'last_name', 'email') #这东西的作用是定义前台要显示哪些信息.
    search_fields = ('first_name', 'last_name')         #定义搜索框
    
class BookAdmin(admin.ModelAdmin):
    list_display = ('title', 'publisher', 'publication_date')
    list_filter = ('publication_date',)                 #右侧有个日期过滤器
    date_hierarchy = 'publication_date'                 #上方有个日期类别选择器
    ordering = ('-publication_date',)                   #哪些字段可以排序
    #fields = ('title', 'authors', 'publisher',)         #哪些字段可以编辑
    filter_horizontal = ('authors',)                    #更强大的多项选择器(多对多)
    raw_id_fields = ('publisher',)                      #让ID代替具体内容(外键一对多的时候,防止加载过多内容)
    
admin.site.register(Publisher)
admin.site.register(Author,AuthorAdmin)
admin.site.register(Book,BookAdmin)